package com.codedancer.campus.manager.api.chatMessage;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codedancer.campus.common.anno.InterfacePermission;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import com.codedancer.campus.manager.api.chatMessage.ro.ChatMessagePageSearchRo;
import com.codedancer.campus.manager.service.IChatMessageService;
import com.codedancer.campus.manager.service.bo.chatMessage.ChatMessagePageSearchBo;
import com.codedancer.campus.manager.service.vo.chatMessage.ChatMessageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/chat-message")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "聊天信息Api", description = "聊天信息Api", tags = "聊天信息Api")
public class ChatMessageApi extends BaseApi {

    @Autowired
    private IChatMessageService chatMessageService;

    @GetMapping("/page/history")
    @ApiOperation("分页查询历史聊天记录")
    @InterfacePermission(encodes = {"superAdmin"})
    public ApiResponse<IPage<ChatMessageVo>> pageHistory(
        @ApiParam(value = "聊天信息分页查询Ro", required = false)
            ChatMessagePageSearchRo chatMessagePageSearchRo) {
        ChatMessagePageSearchBo chatMessagePageSearchBo = BeanUtil.copyProperties(
            chatMessagePageSearchRo, ChatMessagePageSearchBo.class);
        return success(chatMessageService.pageHistory(chatMessagePageSearchBo));
    }
}
